{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_xeza88x"
   },
   "source": [
    "# Classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "graffitiCellId": "id_kndd9lt",
    "graffitiConfig": {
     "executeCellViaGraffiti": "053q9g1_6caz6wu"
    }
   },
   "outputs": [],
   "source": [
    "#include <iostream>\n",
    "\n",
    "class Date {\n",
    "    private:\n",
    "        int day;\n",
    "        int month;\n",
    "        int year;\n",
    "    \n",
    "    public:\n",
    "        void SetDate(int day, int month, int year);\n",
    "        int GetDay();\n",
    "        int GetMonth();\n",
    "        int GetYear();\n",
    "};\n",
    "\n",
    "void Date::SetDate(int day, int month, int year) \n",
    "{\n",
    "    int day_numbers[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n",
    "\n",
    "    if(year % 4 == 0 && year % 100 != 0 || year% 400 == 0)\n",
    "        day_numbers[1]++;\n",
    "\n",
    "    if(year < 1 || day < 1 || month < 1 || month > 12 || day > day_numbers[month - 1])\n",
    "        throw std::domain_error(\"Invalid date!\");\n",
    "\n",
    "    Date::day = day; \n",
    "    Date::month = month; \n",
    "    Date::year = year;\n",
    "}\n",
    "\n",
    "int Date::GetDay() \n",
    "{ \n",
    "    return day; \n",
    "}\n",
    "\n",
    "int Date::GetMonth() \n",
    "{ \n",
    "    return month; \n",
    "}\n",
    "\n",
    "int Date::GetYear() \n",
    "{ \n",
    "    return Date::year; \n",
    "}\n",
    "\n",
    "int main()\n",
    "{\n",
    "   Date date;\n",
    "   date.SetDate(29, 2, 2019);\n",
    "   std::cout << date.GetDay() << \"/\" << date.GetMonth() << \"/\" << date.GetYear()  << \"\\n\";\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_053q9g1"
   },
   "source": [
    "<span class=\"graffiti-highlight graffiti-id_053q9g1-id_6caz6wu\"><i></i><button>Compile & Run</button></span>&nbsp;\n",
    "<span class=\"graffiti-highlight graffiti-id_jaaz7tc-id_oxy4t19\"><i></i><button>Explain</button></span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_umwv915",
    "graffitiConfig": {
     "rows": 6,
     "terminalId": "id_9tqyd9t",
     "type": "terminal"
    }
   },
   "source": [
    "<i>Loading terminal (id_umwv915), please wait...</i>"
   ]
  }
 ],
 "metadata": {
  "graffiti": {
   "firstAuthorId": "8978490740",
   "id": "id_ok19p7y",
   "language": "EN"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
